package main

import (
	"context"
	"encoding/json"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	cards2 "git.900sui.cn/kc/rpcinterface/client/elastic/cards"
	"git.900sui.cn/kc/rpcinterface/interface/task/cards"
	"github.com/streadway/amqp"
)

//维护es的文档shop_items的嵌套文档项目数据
func main() {
	rpcShopItem := new(cards2.ShopCards).Init()

	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("queue.log.shopItemsQue"))
	logs.Info("Environment Variable:MSF_ENV:",kcgin.KcConfig.RunMode)
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("queue.shopItemsQue"), func(msg amqp.Delivery) {
		var itemData cards.ShopItems
		err := json.Unmarshal( msg.Body, &itemData )
		if err != nil{
			return
		}
		reply := false
		err = rpcShopItem.SetItem( context.Background(), &itemData, &reply )
		if err != nil || reply == false{
			utils.Logerr.Println("门店卡项数据设置失败，数据：", string(msg.Body))
		}
		return
	})
	if err != nil {
		panic(err)
	}
}
